From: Florian Müllner Date: Mon, 30 Sep 2013 14:47:52 +0000 (+0200) Subject: messageTray: Add 'Notifications' switch to tray menu X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~3245 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=6e9a2fea8995cd7898124c6fc88f93902caf8417;p=gnome-shell.git messageTray: Add 'Notifications' switch to tray menu According to the designs, the notifications switch was supposed to move from the user menu to the new message tray menu. However so far the new system status implementation only removed the old switch, so add it back in its new place now. https://bugzilla.gnome.org/show_bug.cgi?id=707073 --- diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index e98be02f7..d8d1e36a3 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -1507,9 +1507,33 @@ const MessageTrayMenu = new Lang.Class({ this._tray = tray; + this._presence = new GnomeSession.Presence(Lang.bind(this, function(proxy, error) { + if (error) { + logError(error, 'Error while reading gnome-session presence'); + return; + } + + this._onStatusChanged(proxy.status); + })); + this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) { + this._onStatusChanged(status); + })); + + this._accountManager = Tp.AccountManager.dup(); + this._accountManager.connect('most-available-presence-changed', + Lang.bind(this, this._onIMPresenceChanged)); + this._accountManager.prepare_async(null, Lang.bind(this, this._onIMPresenceChanged)); + this.actor.hide(); Main.layoutManager.addChrome(this.actor); + this._busyItem = new PopupMenu.PopupSwitchMenuItem(_("Notifications")); + this._busyItem.connect('toggled', Lang.bind(this, this._updatePresence)); + this.addMenuItem(this._busyItem); + + let separator = new PopupMenu.PopupSeparatorMenuItem(); + this.addMenuItem(separator); + this._clearItem = this.addAction(_("Clear Messages"), function() { let toDestroy = []; let sources = tray.getSources(); @@ -1541,9 +1565,43 @@ const MessageTrayMenu = new Lang.Class({ settingsItem.connect('activate', function() { tray.close(); }); }, + _onStatusChanged: function(status) { + this._sessionStatus = status; + this._busyItem.setToggleState(status != GnomeSession.PresenceStatus.BUSY); + }, + + _onIMPresenceChanged: function(am, type) { + if (type == Tp.ConnectionPresenceType.AVAILABLE && + this._sessionStatus == GnomeSession.PresenceStatus.BUSY) + this._presence.SetStatusRemote(GnomeSession.PresenceStatus.AVAILABLE); + }, + _updateClearSensitivity: function() { this._clearItem.setSensitive(this._tray.clearableCount > 0); }, + + _updatePresence: function(item, state) { + let status = state ? GnomeSession.PresenceStatus.AVAILABLE + : GnomeSession.PresenceStatus.BUSY; + this._presence.SetStatusRemote(status); + + let [type, s ,msg] = this._accountManager.get_most_available_presence(); + let newType = 0; + let newStatus; + if (status == GnomeSession.PresenceStatus.BUSY && + type == Tp.ConnectionPresenceType.AVAILABLE) { + newType = Tp.ConnectionPresenceType.BUSY; + newStatus = 'busy'; + } else if (status == GnomeSession.PresenceStatus.AVAILABLE && + type == Tp.ConnectionPresenceType.BUSY) { + newType = Tp.ConnectionPresenceType.AVAILABLE; + newStatus = 'available'; + } + + if (newType > 0) + this._accountManager.set_all_requested_presences(newType, + newStatus, msg); + } }); const MessageTrayMenuButton = new Lang.Class({